001 /* 002 * Copyright 2005 Stephen J. McConnell. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 013 * implied. 014 * 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package net.dpml.transit.info; 020 021 import net.dpml.lang.AbstractDirective; 022 023 /** 024 * Description of a host configuration within Transit. 025 * 026 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 027 * @version 1.0.1 028 */ 029 public class HostDirective extends AbstractDirective 030 { 031 private final String m_id; 032 private final int m_priority; 033 private final String m_host; 034 private final String m_index; 035 private final String m_username; 036 private final char[] m_password; 037 private final boolean m_enabled; 038 private final boolean m_trusted; 039 private final String m_layout; 040 private final String m_scheme; 041 private final String m_prompt; 042 043 /** 044 * Creation of a new host description. 045 * @param id a unique resource host identifier 046 * @param priority the host prority 047 * @param host the resource host 048 * @param index the name of an index resource (may be null) 049 * @param username a possibly null username 050 * @param password a possibly null password 051 * @param enabled true if enabled 052 * @param trusted true if trusted 053 * @param layout the name of the layout strategy 054 * @param scheme the security scheme (may be null) 055 * @param prompt authentication prompt (may be null) 056 * @exception NullPointerException if the id, host, or layout are null 057 */ 058 public HostDirective( 059 String id, int priority, String host, String index, String username, char[] password, boolean enabled, 060 boolean trusted, String layout, String scheme, String prompt ) 061 throws NullPointerException 062 { 063 if( null == id ) 064 { 065 throw new NullPointerException( "id" ); 066 } 067 if( null == host ) 068 { 069 throw new NullPointerException( "host" ); 070 } 071 if( null == layout ) 072 { 073 throw new NullPointerException( "layout" ); 074 } 075 076 m_id = id; 077 m_priority = priority; 078 m_host = host; 079 m_index = index; 080 m_username = username; 081 m_password = password; 082 m_enabled = enabled; 083 m_trusted = trusted; 084 m_layout = layout; 085 086 if( null == scheme ) 087 { 088 m_scheme = ""; 089 } 090 else 091 { 092 m_scheme = scheme; 093 } 094 095 if( null == prompt ) 096 { 097 m_prompt = ""; 098 } 099 else 100 { 101 m_prompt = prompt; 102 } 103 104 } 105 106 /** 107 * Return the host identifier. 108 * @return the host id 109 */ 110 public String getID() 111 { 112 return m_id; 113 } 114 115 /** 116 * Return the host priority. 117 * @return the host priority value 118 */ 119 public int getPriority() 120 { 121 return m_priority; 122 } 123 124 /** 125 * Return the resource host. 126 * @return the host 127 */ 128 public String getHost() 129 { 130 return m_host; 131 } 132 133 /** 134 * Return the index resource name. 135 * @return the host index resource name 136 */ 137 public String getIndex() 138 { 139 return m_index; 140 } 141 142 /** 143 * Return the proxy username. 144 * @return the poxy username 145 */ 146 public String getUsername() 147 { 148 return m_username; 149 } 150 151 /** 152 * Return the proxy password. 153 * @return the poxy password 154 */ 155 public char[] getPassword() 156 { 157 return m_password; 158 } 159 160 /** 161 * Return the enabled status. 162 * @return true if enabled 163 */ 164 public boolean getEnabled() 165 { 166 return m_enabled; 167 } 168 169 /** 170 * Return the trusted status. 171 * @return true if trusted 172 */ 173 public boolean getTrusted() 174 { 175 return m_trusted; 176 } 177 178 /** 179 * Return the layout name. 180 * @return the layout key 181 */ 182 public String getLayout() 183 { 184 return m_layout; 185 } 186 187 /** 188 * Return the authentication prompt. 189 * @return the layout key 190 */ 191 public String getPrompt() 192 { 193 return m_prompt; 194 } 195 196 /** 197 * Return the authentication scheme. 198 * @return the scheme 199 */ 200 public String getScheme() 201 { 202 return m_scheme; 203 } 204 205 /** 206 * Compare this instance with a supplied object for equality. 207 * @param other the other object 208 * @return true if the supplied instance is equal to this instance 209 */ 210 public boolean equals( Object other ) 211 { 212 if( super.equals( other ) && ( other instanceof HostDirective ) ) 213 { 214 HostDirective directive = (HostDirective) other; 215 if( !equals( m_id, directive.m_id ) ) 216 { 217 return false; 218 } 219 else if( m_priority != directive.m_priority ) 220 { 221 return false; 222 } 223 else if( m_trusted != directive.m_trusted ) 224 { 225 return false; 226 } 227 else if( m_enabled != directive.m_enabled ) 228 { 229 return false; 230 } 231 else if( !equals( m_host, directive.m_host ) ) 232 { 233 return false; 234 } 235 else if( !equals( m_index, directive.m_index ) ) 236 { 237 return false; 238 } 239 else if( !equals( m_username, directive.m_username ) ) 240 { 241 return false; 242 } 243 else if( !equals( m_layout, directive.m_layout ) ) 244 { 245 return false; 246 } 247 else if( !equals( m_scheme, directive.m_scheme ) ) 248 { 249 return false; 250 } 251 else if( !equals( m_prompt, directive.m_prompt ) ) 252 { 253 return false; 254 } 255 else 256 { 257 if( null == m_password ) 258 { 259 return null == directive.m_password; 260 } 261 else 262 { 263 if( null == directive.m_password ) 264 { 265 return false; 266 } 267 else 268 { 269 return new String( m_password ).equals( new String( directive.m_password ) ); 270 } 271 } 272 } 273 } 274 else 275 { 276 return false; 277 } 278 } 279 280 /** 281 * Compute the instance hashcode value. 282 * @return the hashcode 283 */ 284 public int hashCode() 285 { 286 int hash = m_priority; 287 hash ^= hashValue( m_id ); 288 hash ^= hashValue( new Boolean( m_trusted ) ); 289 hash ^= hashValue( new Boolean( m_enabled ) ); 290 hash ^= hashValue( m_host ); 291 hash ^= hashValue( m_index ); 292 hash ^= hashValue( m_username ); 293 if( null != m_password ) 294 { 295 hash ^= new String( m_password ).hashCode(); 296 } 297 hash ^= hashValue( m_layout ); 298 hash ^= hashValue( m_scheme ); 299 hash ^= hashValue( m_prompt ); 300 return hash; 301 } 302 303 }